<admintpl file="header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li ><a href="{:U('NewsColumnEntrance/index',array($id_type=>$id_val))}">入口列表</a></li>
        <!-- <li><a href="#" onclick="addEntrance('{$column_id}');">添加栏目</a></li> -->
        <li><a href="{:U('NewsColumnEntrance/addEntrance',array($id_type=>$id_val))}" >添加入口</a></li>
		<li class="active"><a href="{:U('NewsColumnEntrance/entranceManageList',array($id_type=>$id_val))}" >入口管理</a></li>
    </ul>
    <div>
    	<span>快捷入口类型&nbsp;&nbsp;&nbsp;</span>
    	<input type="hidden" name="hidden_selected_count" id="hidden_selected_count" value="{$count}">
    	<input type="hidden" name="hidden_type_num" id="hidden_type_num" value="{$type_num}">
    	<input type="hidden" name="id_type" id="id_type" value="{$id_type}">
    	<input type="hidden" name="id_val" id="id_val" value="{$id_val}">
    	<select name="entrance_type" id="entrance_type" selected_type_id="{$first_type_id}"  selected_type_title = "{$first_type_title}">
    		<foreach name="type_list" item="vo" key="keys">
    			<option value="{$vo.type_id}_{$vo.title}" <?php if($first_type_id ==$vo['type_id']) echo "selected"?>>{$vo.title}</option>
    		</foreach>
    	</select>
    	&nbsp;&nbsp;&nbsp;
    	<a href="{:U('NewsColumnEntrance/type_index',array($id_type=>$id_val))}"  class="btn btn-primary">类型管理</a>
    	<a href="#" onclick="chooseEntrance('{$id_type}','{$id_val}');" class="btn btn-primary">设置入口</a>
    	       
    	<?php 
    		if($type_symbol == '1'){
				if($count == $type_num){
		?>
			<a href="#" onclick="releaseEntrance('{$id_type}','{$id_val}');" class="btn btn-primary">发布</a>
		<?php
				}
			}elseif($type_symbol == '2'){
				if($count >= $type_num){
				?>
					<a href="#" onclick="releaseEntrance('{$id_type}','{$id_val}');" class="btn btn-primary">发布</a>
				<?php
				}
			}
    	?>
    	<?php if($count >= $type_num){?><?php }?>
    	
    </div> 
     <p><span style="padding-left:100px;"></span><span style="color:red;">请按照入口类型及数量进行设置</span></p>
    <form class="form-horizontal js-ajax-form" action="{:U('NewsColumn/index')}" method="post">
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th>序号</th>
                <th>入口标题</th>
                <th>副标题</th>
                <th>权重</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <foreach name="list" item="vo" key="keys">
                <tr>
                    <td>{$keys+1}</td>
                    <td>
                    	{$vo.title}
                    </td>
                    <td>
                    	{$vo.subtitle}
                    </td>
                    </td>
                    <td>
                    	 <input type="text" name="weight" id="weight{$vo.entrance_id}" value="{$vo.weight}" disabled="disabled" size="4"  class="input_edit">
                        <a id="edit_weight_{$vo.entrance_id}" href='javascript:void(0);' onclick="update_title('{$vo.entrance_id}','weight')" class="edit_sub">修改</a>
                        <input type="hidden" name="old_weight" id="old_weight_{$vo.entrance_id}" value="{$vo.weight}">
                    </td>
                    <td>
                    <a href="{:U('NewsColumnEntrance/addEntrance',array($id_type=>$id_val,'entrance_id'=>$vo['entrance_id']))}" >编辑</a>
                    <a href='{:U("Admin/NewsColumnEntrance/revoke",array("entrance_id"=>$vo["entrance_id"]))}' class="js-ajax-dialog-btn"
                           data-msg="确定要撤销此入口吗？">撤销</a>
                     </td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </form>
    <div class="pagination">{$page}</div>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
    function update_title(entrance_id,type){
        if(type == 'weight'){
            edit_column = $("#edit_weight_"+entrance_id).html();
            column_befor = $("#old_weight_"+entrance_id).val();//原权重值
            column  = $("#weight"+entrance_id).val(); //现权重值
            now_input_type = $("#weight" + entrance_id); //权重 ID
            now_edit_type  = $("#edit_weight_" + entrance_id);  //修改 按钮ID
        }else if(type == 'title'){
            edit_column = $("#edit_title_"+entrance_id).html();
            column_befor = $("#old_title_"+entrance_id).val();//原栏目名称值
            column  = $("#entrance_title_"+entrance_id).val(); //现栏目名称值
            now_input_type = $("#entrance_title_" + entrance_id); //栏目名称 ID
            now_edit_type  = $("#edit_title_" + entrance_id);  //修改 按钮ID
        }else if(type == 'subtitle'){
            edit_column = $("#edit_subtitle_"+entrance_id).html();
            column_befor = $("#old_subtitle_"+entrance_id).val();//原栏目名称值
            column  = $("#entrance_subtitle_"+entrance_id).val(); //现栏目名称值
            now_input_type = $("#entrance_subtitle_" + entrance_id); //栏目名称 ID
            now_edit_type  = $("#edit_subtitle_" + entrance_id);  //修改 按钮ID
        }

        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == column){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                $.post("{:U('NewsColumnEntrance/editColumnEntrance')}", {type: type, entrance_id: entrance_id, val: column},
                        function (result) {
                            if (result == 1) {
                                now_input_type.attr("disabled", "disabled");
                                now_edit_type.html("修改");
                                location.reload()
                            }else{
                                alert("异常!")
                            }
                        }
                );
            }
        }
    }
    
    $("#entrance_type").change(function(){
    	//获取当前选择的类型是否
    	var selected_count = $("#hidden_selected_count").val();
    	if(selected_count != '0'){
    		layer.confirm('切换发布类型需清空所有已选入口', {
        		btn: ['清空','取消'], //按钮
        		shade: false //不显示遮罩
        		}, function(){
        			var id_type = $("#id_type").val();
        			var id_val = $("#id_val").val();
        	        $.post("{:U('NewsColumnEntrance/emptyEntrance')}", {id_type: id_type, id_val: id_val},
        	                function (result) {
        	                    if (result == 1) {
        	                    	layer.msg('数据一去不复返,骚年重头来过吧~', {icon: 1});
        	                    }else{
        	                        alert("异常!");
        	                    }
        	                    setTimeout(function(){
    	                			location.reload();
    	                		}, 2000);
        	                }
        	        );
        		}, function(){
        			location.reload()
        	});
    	}
    	
    })

    //选择入口
    function chooseEntrance(id_type,id_val){
    	var type_data = $("#entrance_type").find("option:selected").val();
    	var selected_count = $("#hidden_selected_count").find("option:selected").val();
        layer.open({
            type: 2,
            //skin: 'layui-layer-lan',
            title: '选择入口',
            fix: false,
            shadeClose: true,
            maxmin: true,
            area: ['1000px', '500px'],
            content: "<?php echo U('Admin/NewsColumnEntrance/chooseEntrance')?>&type_data="+type_data+'&'+id_type+'='+id_val,
            end: function(){
                location.reload();
            }
        });
    }
    //发布入口
    function releaseEntrance(id_type,id_val){
        $.post("{:U('NewsColumnEntrance/releaseEntrance')}", {id_type: id_type, id_val: id_val},
                function (result) {
                    if (result == 1) {
                    	layer.msg('已发布成功,骚年可去前台观看壮丽变化了~', {icon: 1});
                    }else{
                        alert("异常!")
                    }
                    setTimeout(function(){
            			location.reload();
            		}, 2000);
                }
        );
    }


</script>
</body>
</html>